package com.exercise.beginner.constraint

import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintSet
import androidx.transition.TransitionManager
import com.exercise.beginner.R
import com.exercise.beginner.databinding.ActivityKeyframeOneBinding
import com.exercise.structer.BaseActivity

class ConstraintActivity : BaseActivity<ActivityKeyframeOneBinding>() {
    override val bindingInflater: (LayoutInflater) -> ActivityKeyframeOneBinding
        get() = ActivityKeyframeOneBinding::inflate

    private var flag = false
    override fun initView() {
        binding.button2.setOnClickListener {
            flag = if (!flag) {
                animateToKeyFrameTwo()
                true
            } else {
                animateToKeyFrameOne()
                false
            }
        }
    }

    private fun animateToKeyFrameOne() {
        val constraintSet = ConstraintSet()
        constraintSet.load(this, R.layout.activity_keyframe_one)
        TransitionManager.beginDelayedTransition(binding.root)
        constraintSet.applyTo(binding.root)
    }

    private fun animateToKeyFrameTwo() {
        val constraintSet = ConstraintSet()
        constraintSet.load(this, R.layout.activity_keyframe_two)
        TransitionManager.beginDelayedTransition(binding.root)
        constraintSet.applyTo(binding.root)
    }
}